#{extends 'main.html' /} 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript"
	src=" https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript"
	src=" https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<title>Mark As Duplicates</title>
<link href="../../../public/stylesheets/style_sheet.css"
	rel="stylesheet" type="text/css" />

<script language="javascript"
	src="
https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"
	type="text/javascript"></script>
<script type="text/javascript">


function display(){
	var originalIdeaId = ${id};
	$.getJSON('@{MarkAsDuplicatesController.displayIdeas()}', {'id':originalIdeaId}, function(data){
			var titlesIdeas = {};
		 	var idsIdeas = {};
			var display = "";
			
			
			if(data.titles == "There are no other ideas to mark!!"){
				alert("There are no other ideas to mark!!");
				return;
			}else{
				
				titlesIdeas = data.titles.split("&");
				idsIdeas = data.ids.split("&");
				descriptionsIdeas = data.descriptions.split("&");
				for(var i=1; i<titlesIdeas.length;i=i+1){
				display+="<p><a href=# onclick=\"mark("+idsIdeas[i]+")\">"+titlesIdeas[i]+"</a></p>" +
				descriptionsIdeas[i];
				
				}
				document.getElementById("ideas").innerHTML= "";
				document.getElementById("ideas").innerHTML+=display;
			}
		

});
	
}
function display2(){
	var originalIdeaId = ${id};
	$.getJSON('@{MarkAsDuplicatesController.displayIdeas()}', {'id':originalIdeaId}, function(data){
			var titlesIdeas = {};
		 	var idsIdeas = {};
			var display = "";
		
			
			if(data.titles == "There are no other ideas to mark!!"){
				alert("There are no other ideas to mark!!");
				display3();
			}else{
				
				titlesIdeas = data.titles.split("&");
				idsIdeas = data.ids.split("&");
				for(var i=1; i<titlesIdeas.length;i=i+1){
				display+="<p><a href=# onclick=\"mark("+idsIdeas[i]+")\">"+titlesIdeas[i]+"</a></p>";
				
				}
				document.getElementById("ideas").innerHTML= "";
				document.getElementById("ideas").innerHTML+=display;
			}
		

});
}

function mark(id){
	var duplicateId = id;
	var originalId = ${id};
	$.getJSON('@{MarkAsDuplicatesController.markDuplicatesInIdea()}', {'duplicate':duplicateId, 'original':originalId}, function(data){
		
		var titlesIdeas = {};
	 	var idsIdeas = {};
		var display = "";
	
		if(data.titles == "Failure"){
			alert("Failed to Mark As Duplicates");
			return;
		}else{
			
			titlesIdeas = data.titles.split("&");
			idsIdeas = data.ids.split("&");
		
			display2();
		}
	

});
}
function display3(){
	document.getElementById("ideas").innerHTML ="";
}
function test(){
	document.getElementById("ideas").innerHTML = "helloooooooooooo";
}
</script>

</head>
<body onload="display()">
	
<a href="/TopicIdeaController/checkAuthorizationToViewIdea?ideaId=${id}">Return to Idea</a>
		<h3>Please Select One of the Following Ideas to Mark as a
			Duplicate! *Ideas Previously Marked Will Not Appear In the List Below!</h3>
		<div id="ideas"></div>
		
</body>
</html>